import GlobalData from "../../GlobalData";
import { ListenID } from "../../ListenID";
import NetAdapter from "../../adpapter/NetAdapter";
import { AlertManager, AlertType } from "../../alert/AlertManager";
import { Common_UIPath } from "../../common/Common_Define";
import { MVC } from "../../framework/MVC";
import { Notifier } from "../../framework/Notifier";
import { QRCode } from "../../framework/QRCode/QRCode";
import { QRErrorCorrectLevel } from "../../framework/QRCode/QRConst";
import { Time } from "../../framework/Time";
import { UIManager } from "../../framework/UIManager";
import AdManager from "../../manager/AdManadgr";
import DeviceManager from "../../manager/DeviceManager";
import DouyinManager from "../../manager/DouyinManager";
import { GameVoManager } from "../../manager/GameVoManager";
import { Manager } from "../../manager/Manager";
import { Util } from "../../utils/Util";
import ChaxunItem from "./ChaxunItem";
import PrizeJiangliItem from "./PrizeJiangliItem";
import PrizePoolItem from "./PrizePoolItem";
import RevenueShouYiItem from "./RevenueShouYiItem";
import TixianJIluItem from "./TixianJIluItem";

const { ccclass, property } = cc._decorator;

@ccclass
export default class RevenueView extends MVC.BaseView {
  @property(cc.Node)
  shouyiItem: cc.Node = null;
  @property(cc.Node)
  prizeAll: cc.Node = null;
  @property(cc.Node)
  tixianliluItem: cc.Node = null;

  @property(cc.Node)
  prizeJiangliItem: cc.Node = null;

  @property(cc.Node)
  prizePoolItem: cc.Node = null;



  @property(cc.Node)
  Layout_prizeJiangli : cc.Node = null;
  @property(cc.Node)
  SYListLayout: cc.Node = null;

  @property(cc.Node)
  TixianLayout: cc.Node = null;

  @property(cc.Node)
  TXJiluLayout: cc.Node = null;

  @property(cc.Node)
  YaoqingfuliLayout: cc.Node = null;

  @property(cc.Node)
  prizePoolLayout: cc.Node = null;

  @property(cc.Node)
  layout_chaxun: cc.Node = null;



  @property(cc.Node)
  btnLeft: cc.Node = null;

  @property(cc.Node)
  btnRight: cc.Node = null;

  @property(cc.Label)
  pageNumLabel: cc.Label = null;

  @property(cc.Label)
  lab_coinnum: cc.Label = null;

  @property(cc.Label)
  lab_jingriCoinum: cc.Label = null;

  @property(cc.Label)
  lab_txzh: cc.Label = null;

  @property(cc.Label)
  lab_txxm: cc.Label = null;

  @property(cc.EditBox)
  tixianInput: cc.EditBox = null;

  @property(cc.EditBox)
  dailiInput: cc.EditBox = null;

  @property(cc.EditBox)
  phoneNumberInput: cc.EditBox = null;

  @property(cc.EditBox)
  nicknameInput: cc.EditBox = null;

  @property(cc.Label)
  lab_renzheng: cc.Label = null;

  @property(cc.Label)
  lab_share_link: cc.Label = null;

  @property(cc.Button)
  btn_tixian: cc.Button = null;

  @property(cc.Node)
  qrCode: cc.Node = null;


  @property(cc.Button)
  btn_tixian_huifu_wx: cc.Button = null;
  @property(cc.EditBox)
  huifu_wx_nicknameInput: cc.EditBox = null;

  @property(cc.Node)
  TixianLayout_zhifubao: cc.Node = null;

  @property(cc.Node)
  TixianLayout_huifu_weixin: cc.Node = null;

  @property(cc.Node)
  tixianToggleContainer: cc.Node = null;

  public shouyiPage: number = 1;
  public shouyiMaxPage: number = 100;
  public jiangchiPage: number = 1;
  public jiangchiMaxPage: number = 300;
  public prizeJiangliPage: number = 1;
  public prizeJiangliMaxPage: number = 300;

  public tixianjiluPage: number = 1;
  public tixianjuluMaxPage: number = 100;

  public pageItemNum: number = 8;
  public JilupageItemNum: number = 4;
  public prizeJianglipageItemNum: number = 8; //瓜分奖池记录每页显示多少Item
  public prizeItemNum: number = 7;

  protected changeListener(enable: boolean): void {
    Notifier.changeListener(
      enable,
      ListenID.Revenue_getUserProfit,
      this.getUserProfit,
      this
    );
  }

  /*
   * 打开界面回调，每次打开只调用一
   */
  public onOpen(args: any): void {
    super.onOpen(args);
    this.setInfo(args);
    this.showContainer("fenhongshuoming");
    this.getUserAccountList();

    let date = true ? new Date() : new Date(Time.serverTimeMs);
    let curday = date.getDate();
    if (curday != GameVoManager.getInstance.myUserVo.day) {
      GameVoManager.getInstance.myUserVo.shouyiInter = false;
    }

    if (!GameVoManager.getInstance.myUserVo.shouyiInter) {
      AdManager.inst.playInterstitial(() => {
        console.log("插屏播放完毕");
        GameVoManager.getInstance.myUserVo.shouyiInter = true;
      });
    }
  }

  onClickToggle(event, customdata) {
    this.showContainer(customdata);
  }

  curType = "";
  public showContainer(type: string) {
    console.log("type", type);
    this.curType = type;
    this.hideAll();
    if (type == "shouyi") {
      this.initShowYiList();
      this.SYListLayout.active = true;
      this.btnLeft.active = true;
      this.btnRight.active = true;
      this.pageNumLabel.node.active = true;
      this.userIncome();
    } else if (type == "tixian") {
      if(GlobalData.inst.is_alipay_transfer  && GlobalData.inst.is_huifu_transfer)
      {
        this.TixianLayout.active = true;
        this.tixianToggleContainer.active = true;
        this.TixianLayout_huifu_weixin.active = true;
        this.lab_txzh.string = "提现账号：" + this.phoneNumberInput.string;
        this.lab_txxm.string = "提现姓名：" + this.nicknameInput.string;
        this.getUserProfit();
        // 提现记录
        this.initTixianList();
        this.TXJiluLayout.active = true;
        this.btnLeft.active = true;
        this.btnRight.active = true;
        this.pageNumLabel.node.active = true;
        this.cashrecord();
      }else if(GlobalData.inst.is_huifu_transfer)
      {
        this.tixianToggleContainer.active = false;
        this.showContainerCharge("huifu_weixin") 
      }else if(GlobalData.inst.is_alipay_transfer)
      {
        this.tixianToggleContainer.active = false;
        this.showContainerCharge("zhifubao") 
      }
    } else if (type == "jiangchi") {
      this.initPrizePoolList();
      this.prizePoolLayout.active = true;
      this.btnLeft.active = true;
      this.btnRight.active = true;
      this.pageNumLabel.node.active = true;
      if(this.poolLoading){
        this.prizeAll.active = true;
      }
      this.poolOK = true;
      this.prizePool();
    } else if (type == "fenhongshuoming") {
      this.YaoqingfuliLayout.active = true;
      this.initShare();
      this.dailiInput.string = "";
      if (GlobalData.inst.agent_uid && GlobalData.inst.agent_uid != "0") {
        this.dailiInput.string = GlobalData.inst.agent_uid + "";
      }
    } else if(type == "jiangchishouyi"){
        this.initShowPrizeShouyi();
        this.Layout_prizeJiangli.active = true;
        this.btnLeft.active = true;
        this.btnRight.active = true;
        this.pageNumLabel.node.active = true;
        this.getPrizeJiangli();
    } else if(type == "chaxun"){
      this.initChaxun();
    }
  }
  onClickToggleCharge(event, customdata) {
    this.showContainerCharge(customdata);
  }
  public showContainerCharge(type: string) {
    console.log("type", type);
    this.curType = type;
    // this.hideAll();
    if (type == "huifu_weixin") {
      this.TixianLayout.active = true;
      this.TixianLayout_huifu_weixin.active = true;
      this.TixianLayout_zhifubao.active = false;
      this.getUserProfit();
      // 提现记录
      this.initTixianList();
      this.TXJiluLayout.active = true;
      this.btnLeft.active = true;
      this.btnRight.active = true;
      this.pageNumLabel.node.active = true;
      this.cashrecord();
    } else if (type == "zhifubao") {
      this.TixianLayout.active = true;
      this.TixianLayout_huifu_weixin.active = false;
      this.TixianLayout_zhifubao.active = true;
      this.lab_txzh.string = "提现账号：" + this.phoneNumberInput.string;
      this.lab_txxm.string = "提现姓名：" + this.nicknameInput.string;
      this.getUserProfit();
      // 提现记录
      this.initTixianList();
      this.TXJiluLayout.active = true;
      this.btnLeft.active = true;
      this.btnRight.active = true;
      this.pageNumLabel.node.active = true;
      this.cashrecord();
    } ;
    
  }
  hideAll(){
    this.SYListLayout.active = false;
    this.TixianLayout.active = false;
    this.TXJiluLayout.active = false;
    this.prizePoolLayout.active = false;
    this.prizeAll.active = false;
    this.YaoqingfuliLayout.active = false;
    this.Layout_prizeJiangli.active = false;
    this.btnLeft.active = false;
    this.btnRight.active = false;
    this.pageNumLabel.node.active = false;
    this.layout_chaxun.active = false;
    this.poolOK = false;
  }

  initChaxun(){
    this.hideAll();
    this.layout_chaxun.active = true;
    this.layout_chaxun.getComponent(ChaxunItem).initItem();  
  }

  onClickSYLeft() {
    if (this.curType == "shouyi") {
      if (this.shouyiPage > 1) {
        this.shouyiPage--;
      }
      this.userIncome();
    } else if (this.curType == "tixian") {
      if (this.tixianjiluPage > 1) {
        this.tixianjiluPage--;
      }
      this.cashrecord();
    } else if (this.curType == "jiangchi") {
      if (this.jiangchiPage > 1) {
        this.jiangchiPage--;
      }
      this.prizePool();
    } else if (this.curType == "jiangchishouyi") {
      if (this.prizeJiangliPage > 1) {
        this.prizeJiangliPage--;
      }
      this.getPrizeJiangli();
    }
  }

  onClickSYRight() {
    if (this.curType == "shouyi") {
      if (this.shouyiPage < this.shouyiMaxPage) {
        this.shouyiPage++;
      }
      this.userIncome();
    } else if (this.curType == "tixian") {
      if (this.tixianjiluPage < this.tixianjuluMaxPage) {
        this.tixianjiluPage++;
      }
      this.cashrecord();
    } else if (this.curType == "jiangchi") {
      if (this.jiangchiPage < this.jiangchiMaxPage) {
        this.jiangchiPage++;
      }
      this.prizePool();
    } else if (this.curType == "jiangchishouyi") {
      if (this.prizeJiangliPage < this.prizeJiangliMaxPage) {
        this.prizeJiangliPage++;
      }
      this.getPrizeJiangli();
    }
  }

  onClickTixian() {
    this.btn_tixian.interactable = false;
    if (!this.phoneNumberInput.string) {
      AlertManager.showNormalTips("账号不能为空");
      this.btn_tixian.interactable = true;
      return;
    }
    if (!this.nicknameInput.string) {
      AlertManager.showNormalTips("姓名不能为空");
      this.btn_tixian.interactable = true;
      return;
    }
    if (!this.isNumericString(this.tixianInput.string)) {
      AlertManager.showNormalTips("请输入数字类型");
      this.btn_tixian.interactable = true;
      return;
    }
    let num = Number(this.tixianInput.string);
    if (num < 0.1) {
      AlertManager.showNormalTips("提现金额不能小于0.1");
      this.btn_tixian.interactable = true;
      return;
    }
    let fixedNum = Number(num.toFixed(2)); 
    if(fixedNum < num)
    {
      AlertManager.showNormalTips("提现金额不允许小于分,小数点后2位数");
      this.btn_tixian_huifu_wx.interactable = true;
      return;
    }
    // this.setUserAccount(false);

    // UIManager.Open(Common_UIPath.TixianRenzhengView, MVC.eTransition.Default, MVC.eUILayer.Tips, this.tixianInput.string);
    let param = {
      money: this.tixianInput.string,
      identity: this.phoneNumberInput.string,
      name: this.nicknameInput.string,
    };

    let bindData = {
      type: 1,
      account_bank: "支付宝",
      account: this.phoneNumberInput.string,
      name: this.nicknameInput.string,
    };

    AlertManager.showAlert(AlertType.SELECT, {
      reasonDesc: `提现`,
      wayDesc: "是否提现" + this.tixianInput.string + "？",
      confirmText: "是",
      cancelText: "否",
      confirm: () => {
        if (
          this.account + "" != this.phoneNumberInput.string ||
          this.account_name + "" !== this.nicknameInput.string
        ) {
          NetAdapter.setUserAccount(bindData)
            .then((res: any) => {
              console.log("setUserAccount", res);
              this.getUserAccountList();
              // AlertManager.showNormalTips(res.msg);
              NetAdapter.tixian(param).then((res) => {
                console.log("提现", JSON.stringify(res));
                AlertManager.showNormalTips("提现成功");
                this.getUserProfit();
                this.btn_tixian.interactable = true;
              })
              .catch((err)=>{
                this.btn_tixian.interactable = true;
              })
              ;
            })
            .catch((err) => {
              this.btn_tixian.interactable = true;
            });
        } else {
          NetAdapter.tixian(param).then((res) => {
            console.log("提现", JSON.stringify(res));
            AlertManager.showNormalTips("提现成功");
            this.getUserProfit();
            this.btn_tixian.interactable = true;
          }).catch((err) => {
            this.btn_tixian.interactable = true;
          });
        }
      },
      cancel :()=> {
        this.btn_tixian.interactable = true;
      }
    });
  }

  private handleWithdrawHuiFu(param: any, bindData: any, needSetAccount: boolean) {
    if (needSetAccount) {
      NetAdapter.setUserAccount(bindData)
        .then((res: any) => {
          console.log("setUserAccount", res);
          this.getUserAccountList();
          this.executeWithdraw(param);
        })
        .catch((err) => {
          this.btn_tixian_huifu_wx.interactable = true;
        });
    } else {
      this.executeWithdraw(param);
    }
  }

  private executeWithdraw(param: any) {
    NetAdapter.withdrawHuiFu(param).then((res) => {
      console.log("汇服八方提现", JSON.stringify(res));
      let packageInfo = res.data.package_info;
      console.log("汇服八方 packageInfo", packageInfo);
      console.log("汇服八方提现 platform_order_id", res.data.platform_order_id);
      console.log("汇服八方提现 order_id", res.data.order_id);
      // 判断平台
      if (cc.sys.isNative) {
        if (cc.sys.os === cc.sys.OS_ANDROID) {
          // Android 使用 Intent 跳转
          jsb.reflection.callStaticMethod("com/jingyingxiaobing/blueclient/AppActivity", "openChargeHuihu", "(Ljava/lang/String;)V", packageInfo);
        } else if (cc.sys.os === cc.sys.OS_IOS) {
          // iOS 跳转
          jsb.reflection.callStaticMethod("AppController", "openChargeHuihu:", packageInfo);
        }
      }
      //每10秒获取临时数据，总共调用6次
      this.schedule(() => {
        this.getUserProfit();
      }, 10, 6);
      this.btn_tixian_huifu_wx.interactable = true;
    }).catch((err) => {
      this.btn_tixian_huifu_wx.interactable = true;
    });
  }

  //汇服八方微信提现
  onClickTixianhuifuWx() {
    this.btn_tixian_huifu_wx.interactable = false;
    if (!this.huifu_wx_nicknameInput.string) {
      AlertManager.showNormalTips("姓名不能为空");
      this.btn_tixian_huifu_wx.interactable = true;
      return;
    }
    if (!this.isNumericString(this.tixianInput.string)) {
      AlertManager.showNormalTips("请输入数字类型");
      this.btn_tixian_huifu_wx.interactable = true;
      return;
    }
    let num = Number(this.tixianInput.string);
    console.log("onClickTixianhuifuWx ",num)
    if (num < 0.1) {
      AlertManager.showNormalTips("提现金额不能小于0.1");
      this.btn_tixian_huifu_wx.interactable = true;
      return;
    }
    let fixedNum = Number(num.toFixed(2)); 
    if(fixedNum < num)
    {
      AlertManager.showNormalTips("提现金额不允许小于分,小数点后2位数");
      this.btn_tixian_huifu_wx.interactable = true;
      return;
    }

    let param = {
      money: this.tixianInput.string,
      name: this.huifu_wx_nicknameInput.string,
    };
    
    let bindData = {
      type: 4,
      account: GlobalData.inst.uid,
      account_bank: "汇服八方",
      name: this.huifu_wx_nicknameInput.string,
    };
    AlertManager.showAlert(AlertType.SELECT, {
      reasonDesc: `提现`,
      wayDesc: "是否提现" + this.tixianInput.string + "？",
      confirmText: "是",
      cancelText: "否",
      confirm: () => {
        const needSetAccount = this.account_name_huifu_wx + "" !== this.huifu_wx_nicknameInput.string;
        this.handleWithdrawHuiFu(param, bindData, needSetAccount);
      },
      cancel :()=> {
        this.btn_tixian_huifu_wx.interactable = true;
      }
    });
  }
  onClickShareUrl() {
    DouyinManager.inst.shareUrlAndroid(this.lab_share_link.string);
  }

  onCLickShareImg() {
    DouyinManager.inst.shareAndroid(this.node);
  }

  onClickCopyUrl() {
    DeviceManager.inst.copyText(this.lab_share_link.string, () => {
      AlertManager.showNormalTips("复制成功");
    }, () => {
      AlertManager.showNormalTips("复制失败");
    });
  }

  onDaliConfirm() {
    if (GlobalData.inst.agent_uid != "" && GlobalData.inst.agent_uid != "0") {
      AlertManager.showNormalTips("你已经绑定过了！");
    } else {
      let agent_uid = this.dailiInput.string;
      NetAdapter.userUpdateDaili({ agent_uid: agent_uid })
        .then((res) => {
          Util.logExt(res, "绑定成功");
          GlobalData.inst.agent_uid = agent_uid;
          AlertManager.showNormalTips("绑定成功！");
        })
        .catch((err) => {
          Util.logExt(err, "绑定失败");
          // AlertManager.showNormalTips("绑定失败");
        });
    }
  }

  initShare() {
    var qrcode = new QRCode(-1, QRErrorCorrectLevel.H);
    let dataUrl =
      "https://jyxb-server.ruishangkeji.cn/app/index_app.html" +
      "?agent_uid=" +
      GlobalData.inst.uid;
    qrcode.addData(dataUrl);
    qrcode.make();

    var ctx = this.qrCode.getComponent(cc.Graphics);
    ctx.fillColor = cc.Color.BLACK;

    var tileW = this.qrCode.width / qrcode.getModuleCount();
    var tileH = this.qrCode.height / qrcode.getModuleCount();

    // draw in the Graphics
    for (var row = 0; row < qrcode.getModuleCount(); row++) {
      for (var col = 0; col < qrcode.getModuleCount(); col++) {
        if (qrcode.isDark(row, col)) {
          var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW);
          var h = Math.ceil((row + 1) * tileW) - Math.floor(row * tileW);
          ctx.rect(Math.round(col * tileW), Math.round(row * tileH), w, h);
          ctx.fill();
        }
      }
    }

    this.lab_share_link.string = dataUrl;
  }

  isNumericString(input: string): boolean {
    // 正则表达式，匹配整数或小数（包括正负号和科学记数法）
    const numericPattern = /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/;

    // 测试输入的字符串是否符合正则表达式
    return numericPattern.test(input);
  }

  userIncome() {
    this.SYListLayout.children.forEach((item) => (item.active = false));

    NetAdapter.userIncome({
      page: this.shouyiPage,
      pageNumber: this.pageItemNum,
    })
      .then((res: any) => {
        console.log("userIncome", res);
        this.shouyiMaxPage = Math.ceil(
          parseInt(res.pageTotal) / this.pageItemNum
        );
        this.pageNumLabel.string = `${this.shouyiPage}/${this.shouyiMaxPage}`;
        for (let index = 0; index < res.list.length; index++) {
          let item = this.SYListLayout.children[index];
          item.getComponent(RevenueShouYiItem).setData(res.list[index]);
        }
      })
      .catch((err) => {});
  }

  getPrizeJiangli(){
    NetAdapter.prizePoolLog({page: this.prizeJiangliPage, num: this.pageItemNum})
    .then((res: any) => {
      console.log("prizePoolLog", res);
      this.prizeJiangliMaxPage = Math.ceil(
        parseInt(res.page_total) / this.pageItemNum
      );
      this.pageNumLabel.string = `${this.prizeJiangliPage}/${this.prizeJiangliMaxPage}`;
      for (let index = 0; index < res.list.length; index++) {
        let item = this.Layout_prizeJiangli.children[index];
        item.getComponent(PrizeJiangliItem).setData(res.list[index]);
      }
    })
  }

  getUserProfit() {
    NetAdapter.userIncome({
      page: 1,
      pageNumber: 1,
    })
      .then((res: any) => {
        console.log("getUserProfit", res);
        this.lab_coinnum.string = "余额：" + (res.userinfo.commission || 0);
        this.lab_jingriCoinum.string = "今日收益：" + (res.revenue_today || 0);
      })
      .catch((err) => {});
  }

  setUserAccount(showTip = true) {
    // this.
    if (!this.phoneNumberInput.string && showTip) {
      AlertManager.showNormalTips("账号不能为空");
      return;
    }
    if (!this.nicknameInput.string && showTip) {
      AlertManager.showNormalTips("姓名不能为空");
      return;
    }
    let data = {
      type: 1,
      account_bank: "支付宝",
      account: this.phoneNumberInput.string,
      name: this.nicknameInput.string,
    };
    NetAdapter.setUserAccount(data)
      .then((res: any) => {
        console.log("setUserAccount", res);
        this.getUserAccountList();
        AlertManager.showNormalTips(res.msg);
      })
      .catch((err) => {});
  }

  account = "";
  account_name = "";
  account_name_huifu_wx = "";
  getUserAccountList() {
    // 提现账号类型：1支付宝，2微信，3银行卡，4汇付八方
    NetAdapter.getUserAccountList()
      .then((res: any) => {
        console.log("getUserAccountList", res);
        let list: any = res;
        console.log("getUserAccountList list", JSON.stringify(list));
        list.forEach(itemInfo => {
          if(itemInfo.type ==1)
          {
            //支付宝
            this.account = itemInfo.account;
            this.account_name = itemInfo.name;
            
            this.phoneNumberInput.string = itemInfo.account;
            this.nicknameInput.string = itemInfo.name;
            console.log("getUserAccountList this.phoneNumberInput.string", this.phoneNumberInput.string);
          }else if(itemInfo.type ==4)
          {
            //汇服八方
            this.account_name_huifu_wx = itemInfo.name;
            this.huifu_wx_nicknameInput.string =itemInfo.name;
          }
        });

      })
      .catch((err) => {});
  }

  cashrecord() {
    NetAdapter.cashrecord({
      page: this.tixianjiluPage,
      pageNumber: this.JilupageItemNum,
    })
      .then((res: any) => {
        console.log("cashrecord", res);
        this.tixianjuluMaxPage = Math.ceil(
          parseInt(res.total) / this.JilupageItemNum
        );
        this.pageNumLabel.string = `${this.tixianjiluPage}/${this.tixianjuluMaxPage}`;
        for (let index = 0; index < res.list.length; index++) {
          let item = this.TXJiluLayout.children[index];
          item.getComponent(TixianJIluItem).setData(res.list[index]);
          console.log("cashrecord执行");
        }
      })
      .catch((err) => {});
  }

  private fristPool = true;

  private poolOK = false;
  private poolLoading = false;
  /**
   * 奖池更新
   */
  prizePool() {
    NetAdapter.jiangchi({})
      .then((res) => {
        console.log("prizePool", res);
        this.jiangchiMaxPage = Math.ceil(
          parseInt(res.info.list.length) / this.prizeItemNum
        );
        // 显示奖池总额
        this.poolLoading = true;
        if(this.poolOK){
          this.prizeAll.active = true;
          // if(this.poolLoading){
          //   this.prizeAll.active = false;
          //   this.poolLoading = false;
          // }
        }
        this.prizeAll.getChildByName("prizeNum").getComponent(cc.Label).string =
        res.info.total;


        
        this.pageNumLabel.string = `${this.jiangchiPage}/${this.jiangchiMaxPage}`;
        for (
          let i = 0;
          this.jiangchiPage != this.jiangchiMaxPage
            ? i < this.prizeItemNum
            : i < res.info.list.length % this.prizeItemNum;
          i++
        ) {
          let j = (this.jiangchiPage - 1) * this.prizeItemNum;
          let item = this.prizePoolLayout.children[i];
          item.getComponent(PrizePoolItem).setData(res.info.list[j + i]);
        }
        // 判断是否在榜上
        if (this.fristPool) {
          this.fristPool = false;
          for (let i = 0; i < res.info.list.length; i++) {
            let item = res.info.list[i];
            if (item.uid == GlobalData.inst.uid) {
              GlobalData.inst.findMe_prize = true;
              // return;
            }
          }
          if (
            res.info.list.length < 100 &&
            GlobalData.inst.findMe_prize == false
          ) {
            // return
            NetAdapter.addPrizePool()
              .then((res: any) => {
                let msg = res.msg;
                // if (res.code == 0) {
                  msg = msg || "入驻成功";
                // }
                console.log("addPrizePool", res);
                AlertManager.showNormalTips(msg);
                this.prizePool();
              })
              .catch((errs) => {
                console.log("奖池错误", errs);
              });
          }
        }

      })
      .catch((err) => {});
  }

  private initShowYiListOK = false;
  public initShowYiList() {
    if (this.initShowYiListOK) {
      return;
    }
    this.initShowYiListOK = true;
    this.SYListLayout.active = true;
    this.SYListLayout.removeAllChildren();
    for (let i = 0; i < this.pageItemNum; i++) {
      let item = cc.instantiate(this.shouyiItem);
      item.active = false;
      item.getComponent(RevenueShouYiItem).registerTouch();
      item.parent = this.SYListLayout;
    }
    this.SYListLayout.active = false;
  }
  // 奖池收益初始化
  private initShowPrizeShouyiOK = false;
  public initShowPrizeShouyi() {
    if (this.initShowPrizeShouyiOK) {
      return;
    }
    this.initShowPrizeShouyiOK = true;
    this.Layout_prizeJiangli.active = true;
    this.Layout_prizeJiangli.removeAllChildren();
    for (let i = 0; i < this.JilupageItemNum; i++) {
      let item = cc.instantiate(this.prizeJiangliItem);
      item.active = false;
      item.getComponent(PrizeJiangliItem).registerTouch();
      item.parent = this.Layout_prizeJiangli;
    }
    this.Layout_prizeJiangli.active = false;
  }

  private initPrizePoolListOK = false;

  private initPrizePoolList() {
    if (this.initPrizePoolListOK) return;
    this.initPrizePoolListOK = true;
    this.prizePoolLayout.active = true;
    this.prizePoolLayout.removeAllChildren();
    for (let i = 0; i < this.prizeItemNum; i++) {
      let item = cc.instantiate(this.prizePoolItem);
      item.active = false;
      item.getComponent(PrizePoolItem).registerTouch();
      item.parent = this.prizePoolLayout;
    }
    this.prizePoolLayout.active = false;
  }

  private initTixianListOK = false;
  public initTixianList() {
    if (this.initTixianListOK) {
      return;
    }
    this.initTixianListOK = true;
    this.TXJiluLayout.active = true;
    this.TXJiluLayout.removeAllChildren();
    for (let i = 0; i < this.JilupageItemNum; i++) {
      let item = cc.instantiate(this.tixianliluItem);
      item.active = false;
      item.getComponent(TixianJIluItem).registerTouch();
      item.parent = this.TXJiluLayout;
    }
    this.TXJiluLayout.active = false;
  }

  /*
   * 关闭界面回调，每次打开只调用一次
   */
  public onClose(): void {
    Manager.audio.playAudio(501);
    super.onClose();
  }

  public onBack() {
    this.onClose();
  }
}
